/**
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
 * The Universal Permissive License (UPL), Version 1.0
 */
"use strict";
/*
 Copyright 2013 jQuery Foundation and other contributors
 Released under the MIT license.
 http://jquery.org/license
*/
define(["ojs/ojcore","jquery","ojs/ojeditablevalue","jqueryui-amd/widgets/draggable","ojs/ojtouchproxy"],function(a,g){(function(){a.Ra("oj.ojSlider",g.oj.editableValue,{defaultElement:"\x3cinput\x3e",version:"1.0.1",widgetEventPrefix:"oj",options:{distance:0,max:100,min:0,orientation:"horizontal",readOnly:!1,disabled:!1,step:1,type:"fromMin",value:0,rawValue:void 0},Uaa:5,Lda:null,gg:function(){return"rtl"===a.D.In()},_ComponentCreate:function(){this._super();this.z$=!1;this.element.is("INPUT")?
(this.z$=!0,this.element[0].style&&(this.OEa=this.element[0].style.cssText),this.x$=this.element.css("display"),this.element.css("display","none"),this.an=this.oe?g(this.oe):g(this.element).wrap("\x3cdiv\x3e \x3c/div\x3e").parent()):this.an=this.element;this.B5()},B5:function(){this.Paa=[];this.bj=null;var a="oj-slider ",a=this.Hd()?a+"oj-slider-vertical":a+"oj-slider-horizontal",a=a+" oj-component oj-form-control";this.options.gO&&(a+=" oj-read-only");this.options.disabled&&(a+=" oj-disabled");this.an.removeClass();
this.an.addClass(a);this.ei="range"===this.options.type?!0:!1;this.W4();this.vsa();this.Nra();this.Eqa();this.rsa();this.ysa();this.bF();this.Bn()},Nh:function(){this._super();this.rz();var a,c=this.bna();if(c){a=this.an.find(".oj-slider-thumb");var d=c.attr("id");d||(d=c.attr("for"));a.attr("aria-labelledby",d);1<c.length&&1<a.length&&a[1].attr("aria-labelledby",String(d))}else if(c=this.element.attr("aria-label"))a=this.an.find(".oj-slider-thumb"),a.attr("aria-label",c)},bna:function(){var a=this.nua();
if(null!==a&&0!==a.length)return a;a=this.mua();return null!==a&&0!==a.length?a:null},mua:function(){var a=this.element.prop("id");if(void 0!==a){var c=g("label[for\x3d'"+a+"']");if(0<c.length)return c;a="span[for\x3d'"+a+"']";if(0!==g(a).length)return g(a)}return null},nua:function(){var a=this.element.attr("aria-labelledby");if(void 0!==a){var c=g("label[id\x3d'"+a+"']");if(0<c.length)return c;a=g("span[id\x3d'"+a+"']");if(0<a.length)return a}return null},widget:function(){return this.an},Hl:function(a){this.Lda=
a},Si:function(){return this.Lda},uJ:function(){return this.element[0].id},ZT:function(a){return this.uJ()+"-thumb"+a},u7:function(){return this.uJ()+"-barValue"},pua:function(){return this.uJ()+"-barBack"},Rva:function(){return this.uJ()+"-sliderWrapper"},ysa:function(){var a,c,d="",e="class\x3d'oj-slider-thumb ui-state-default' tabindex\x3d'0' role\x3d'slider'"+("aria-valuemin \x3d '"+this.Me()+"' ")+("aria-valuemax \x3d '"+this.uh()+"' ")+"\x3e\x3c/span\x3e",f=[];c=this.ei?2:1;for(a=0;a<c;a++)d=
"\x3cspan "+("id\x3d'"+this.ZT(a)+"' ")+e,f.push(d);this.cj=g(f.join("")).appendTo(this.fp);this.mt=this.cj.eq(0);var h=this;a=0;this.cj.each(function(){g(this).data("oj-slider-thumb-index",a++);h.Hd()&&g(this).attr("aria-orientation","vertical");h.options.disabled?(g(this).attr("aria-disabled","true"),g(this).removeAttr("tabindex")):g(this).removeAttr("aria-disabled");h.options.readOnly?g(this).attr("title","read only"):g(this).removeAttr("title")})},vsa:function(){var a=this.Rva(),c=this.an.find("#"+
a);c.length&&c.remove();this.fp=g("\x3cdiv\x3e\x3c/div\x3e");g(this.fp).attr("id",a);this.fp.addClass("oj-slider-container");this.element.after(this.fp);this.fp[0].style.cssText=this.OEa},Nra:function(){var a=this.pua(),c=this.an.find("#"+a);c.length&&c.remove();this.Je=g("\x3cdiv\x3e\x3c/div\x3e");c="oj-slider-bar";c=this.Hd()?c+" oj-slider-vertical":c+" oj-slider-horizontal";g(this.Je).attr("id",a);this.Je.addClass(c);this.fp.append(this.Je);var d=this;this.Je.on("mousedown"+d.eventNamespace,function(a){d.oca(a);
d.$D(a);d.eD().focus()})},Eqa:function(){this.options.type&&(this.options.value?this.ei&&2!==this.options.value.length&&(this.options.value=[0<this.options.value.length?this.options.value[0]:this.Me(),this.uh()],this.option("value",this.options.value,{_context:{Cd:!0,kb:!0}})):(this.options.value=this.ei?[this.Me(),this.uh()]:this.Me(),this.option("value",this.options.value,{_context:{Cd:!0,kb:!0}})))},rsa:function(){var a=this.options,c="";if(a.type){this.Ec=g("\x3cdiv\x3e\x3c/div\x3e");g(this.Ec).attr("id",
this.u7());this.fp.append(this.Ec);var c="oj-slider-range oj-slider-bar-value",d=this;this.Ec.on("mousedown"+d.eventNamespace,function(a){d.oca(a);d.$D(a);d.eD().focus()});this.Ec=this.fp.find("#"+this.u7());var e="";"fromMin"===a.type?e=" oj-slider-range-min":"fromMax"===a.type&&(e=" oj-slider-range-max");this.Ec.addClass(c+e)}else this.Ec&&this.Ec.remove(),this.Ec=null},vEa:function(b){this.iX=a.Fg.Pea(b)},ZEa:function(b){a.Fg.Cja(b)},Bn:function(){this.Nu()&&this._hoverable(this.an);this.cj.toArray().forEach(function(a){a=
g(a);this.Zu(a);this._on(a,this.bFa);this.vEa(a);this._focusable({element:a,applyHighlight:!0})},this)},_GetMessagingLauncherElement:function(){return this.an},Xf:function(){return this.eD()},u6:function(){this.cj.toArray().forEach(function(a){a=g(a);this.ZEa(a)},this);this.Ec&&this.Ec.remove();this.fp&&this.fp.remove()},xFa:function(){a.D.unwrap(this.element,this.an);this.element.css("display",this.x$);this.iy(this.element)},_destroy:function(){this.u6();this.xFa();return this._super()},oca:function(a){var c,
d,e=this.options,f=0,h=this;this.y5=this.mt;if(e.disabled||e.readOnly)return!1;c=this.vva({x:a.pageX,y:a.pageY});d=this.uh()-this.Me()+1;this.ei&&this.cj.each(function(a){var b=Math.abs(c-h.yv(a));if(d>b||d===b&&(a===h.Sza||h.yv(a)===e.min))d=b,this.y5=g(this),f=a});this.bj=f;if(!this.y5)return!0;this.cj.hasClass("ui-state-hover")||this.ep(a,f,c);this.eD().addClass("oj-active").focus();this.Ec.addClass("oj-active");return!0},Mya:function(a,c){var d=this.options;if(d.disabled||d.readOnly)return!1;
c.removeClass("oj-focus-highlight");c.addClass("oj-active").focus();this.Ec.addClass("oj-active");return!0},zAa:function(a,c){var d=this.y8(c);this.ep(a,this.bj,d,!0);d=100*this.T7(c);this.ei?this.oda(d,this.bj):this.lda(d);return!1},$D:function(a,c){this.cj.removeClass("oj-active");this.Ec.removeClass("oj-active");var d=this.y8(c);this.ep(a,this.bj,d);this.Mk(a,this.bj,!1);this.bj=null;return!1},Hd:function(){return"vertical"===this.options.orientation},A8:function(a){1<a&&(a=1);0>a&&(a=0);this.Hd()&&
(a=1-a);return a},vva:function(a){var c=this.Wua(a);a=this.uh()-this.Me();this.gg()&&!this.Hd()&&(c=1-c);return this.Yk(this.Me()+c*a)},Wua:function(a){var c;this.Hd()?(c=this.Je.height(),a=a.y-this.Je.offset().top):(c=this.Je.width(),a=a.x-this.Je.offset().left);return 0===c?1:c=this.A8(a/c)},eD:function(){return this.ei?g(this.cj[this.bj]):this.mt},T7:function(a){var c;(c=a)||(c=this.eD());this.Hd()?(a=c.outerHeight()/2,a=c.offset().top+a,c=this.Je.height(),a-=this.Je.offset().top):(a=c.outerWidth()/
2,a=c.offset().left+a,c=this.Je.width(),a-=this.Je.offset().left);return 0===c?1:c=this.A8(a/c)},y8:function(a){var c;a=this.T7(a);c=this.uh()-this.Me();this.gg()&&!this.Hd()&&(a=1-a);return this.Yk(this.Me()+a*c)},wva:function(a){return this.yv(a?0:1)},rva:function(a,c,d){return 2===this.options.value.length&&(0===a&&c>d||1===a&&c<d)?d:c},ep:function(a,c,d,e){var f;this.ei?(f=this.wva(c),d=this.rva(c,d,f),d!==this.yv(c)&&this.$Da(a,c,d,e)):d!==this.Q8()&&(this.iEa(a,d,e),e||this.z$&&this.element.val(d))},
iEa:function(a,c,d){this.NK=this.Yk(c);d||(this.wc(this.NK,a),this.bF());this.jq(this.NK,a)},Mk:function(a,c,d){this.ei?(this.maa=this.sva(c,this.Paa[c]),this.jq(this.maa,a),d||this.wc(this.maa,a)):(this.jq(this.NK,a),d||this.wc(this.NK,a));this.Sza=c},sva:function(a,c){var d,e;d=this.options.value.slice();for(e=0;e<d.length;e+=1)d[e]=this.Yk(d[e]);a===this.bj&&(d[a]=c);return d},Q8:function(){return this.j9()},yv:function(a){return this.awa(a)},$Da:function(a,c,d,e){this.Paa[c]=this.Yk(d);this.Mk(a,
c,e);e||this.bF()},_setOption:function(a,c,d){"value"===a&&(Array.isArray(c)?isNaN(c[0])?(this.ei=!1,this.Yo(a,c[0])):this.ei=!0:(this.ei=!1,this.Yo(a,c)));c="max"===a||"min"===a?this.Yo(a,c):"step"===a?this.iE(c):c;"disabled"!==a&&this._super(a,c,d);"readOnly"===a&&(this.options.gO=c);"disabled"===a&&(this.options.disabled=c);switch(a){case "value":this.bF();this.rz();break;case "min":case "max":this.W4();this.bF();this.rz();break;case "orientation":case "readonly":case "step":case "type":case "disabled":this.MBa()}},
MBa:function(){this.u6();this.B5();this.Nh()},j9:function(){var a=this.options.value;return a=this.Yk(a)},awa:function(a){return this.Yk(this.options.value[a])},Yk:function(a){if(a<=this.Me())return this.Me();if(a>=this.uh())return this.uh();var c=0<this.options.step?this.options.step:1,d=(a-this.Me())%c;a-=d;2*Math.abs(d)>=c&&(a+=0<d?c:-c);return parseFloat(a.toFixed(5))},W4:function(){var a=this.Me();this.max=0!==(this.options.max-a)/this.options.step%1?this.options.max-(this.options.max-a)%this.options.step:
this.options.max},Me:function(){return this.options.min},uh:function(){return this.max},U7:function(){var a;a=0<this.options.step?(this.uh()-this.Me())/this.options.step:100;a=(this.Hd()?this.Je.height():this.Je.width())/a;1>a&&(a=1);return this.Hd()?[1,a]:[a,1]},$T:function(a){return(this.yv(a)-this.Me())/(this.uh()-this.Me())},bF:function(){var a,c,d,e;this.ei?this.cj.toArray().forEach(function(c,d){var e=g(c);a=100*this.$T(d);this.gg()&&!this.Hd()&&(a=100-a);this.Hd()?g(e).css({top:100-a+"%"}):
g(e).css({left:a+"%"});g(e).attr("aria-valuenow",this.yv(d));this.oda(a,d)},this):(c=this.j9(),d=this.Me(),e=this.uh(),a=e!==d?(c-d)/(e-d)*100:0,this.gg()&&!this.Hd()&&(a=100-a),this.Hd()?this.mt.css({top:100-a+"%"}):this.mt.css({left:a+"%"}),g(this.mt).attr("aria-valuenow",c),this.lda(a))},lda:function(a){var c=this.options.type;this.Hd()?("fromMin"===c&&this.Ec.css({height:a+"%"}),"fromMax"===c&&this.Ec.css({height:100-a+"%"})):this.gg()?("fromMin"===c&&this.Ec.css({width:100-a+"%"}),"fromMax"===
c&&this.Ec.css({width:a+"%"})):("fromMin"===c&&this.Ec.css({width:a+"%"}),"fromMax"===c&&this.Ec.css({width:100-a+"%"}))},oda:function(a,c){var d=this.Ec.attr("id");if(0===c)switch(d=100*this.$T(1),this.options.type){case "fromMin":this.Hd()?this.Ec.css({height:a+"%"}):this.Ec.css({width:a+"%"});break;case "range":this.Hd()?(this.Ec.css({top:100-d+"%"}),this.Ec.css({height:d-a+"%"})):this.gg()?(this.Ec.css({left:100-d+"%"}),this.Ec.css({width:d-(100-a)+"%"})):(this.Ec.css({left:a+"%"}),this.Ec.css({width:d-
a+"%"}))}else{var e=100*this.$T(0);switch(this.options.type){case "fromMax":this.Hd()?this.Ec.css({height:100-a+"%"}):this.Ec.css({width:100-a+"%"});break;case "range":this.Hd()?document.getElementById(d)&&(this.Ec.css({top:100-a+"%"}),this.Ec.css({height:a-e+"%"})):this.gg()?document.getElementById(d)&&(this.Ec.css({left:a+"%"}),this.Ec.css({width:-a+100-e+"%"})):document.getElementById(d)&&this.Ec.css({width:a-parseInt(document.getElementById(d).style.left,10)+"%"})}}},bFa:{keydown:function(a){var c,
d,e,f=g(a.target).data("oj-slider-thumb-index");this.bj=f;switch(a.keyCode){case g.ui.keyCode.HOME:case g.ui.keyCode.END:case g.ui.keyCode.PAGE_UP:case g.ui.keyCode.PAGE_DOWN:case g.ui.keyCode.UP:case g.ui.keyCode.RIGHT:case g.ui.keyCode.DOWN:case g.ui.keyCode.LEFT:a.preventDefault(),g(a.target).addClass("oj-active")}e=this.options.step;c=this.ei?d=this.yv(f):d=this.Q8();switch(a.keyCode){case g.ui.keyCode.HOME:d=this.Me();break;case g.ui.keyCode.END:d=this.uh();break;case g.ui.keyCode.PAGE_UP:d=
this.Yk(c+(this.uh()-this.Me())/this.Uaa);break;case g.ui.keyCode.PAGE_DOWN:d=this.Yk(c-(this.uh()-this.Me())/this.Uaa);break;case g.ui.keyCode.UP:if(c===this.uh())return;d=this.Yk(c+e);break;case g.ui.keyCode.RIGHT:if(!this.gg()||this.Hd()){if(c===this.uh())return;c+=e}else{if(c===this.Me())return;c-=e}d=this.Yk(c);break;case g.ui.keyCode.DOWN:if(c===this.Me())return;d=this.Yk(c-e);break;case g.ui.keyCode.LEFT:if(!this.gg()||this.Hd()){if(c===this.Me())return;c-=e}else{if(c===this.uh())return;c+=
e}d=this.Yk(c)}this.ep(a,f,d)},keyup:function(a){switch(a.keyCode){case g.ui.keyCode.HOME:case g.ui.keyCode.END:case g.ui.keyCode.PAGE_UP:case g.ui.keyCode.PAGE_DOWN:case g.ui.keyCode.UP:case g.ui.keyCode.RIGHT:case g.ui.keyCode.DOWN:case g.ui.keyCode.LEFT:var c=g(a.target).data("oj-slider-thumb-index");this.bj=c;this.Mk(a,c,!1);g(a.target).removeClass("oj-active");this.bj=null}}},Yf:function(b,c){var d=this.options,e=this;this._superApply(arguments);a.Fe.Cp([{ha:"disabled",Sd:!0},{ha:"value"},{ha:"title"},
{ha:"min"},{ha:"max"},{ha:"step"}],c,this,function(a){for(var b=["value","step","min","max"],c=0;c<b.length;c++){var g=b[c],m=g in a?a[g]:d[g];null!=m&&("step"===g?a[g]=e.iE(m):"min"===g||"max"===g?a[g]=e.Yo(g,m):"value"===g&&(Array.isArray(m)?a[g]=m:a[g]=e.Yo(g,m)))}});if(void 0===d.value)throw Error(this.F("noValue"));if(null!=d.min&&null!=d.max){if(d.max<d.min)throw Error(this.F("maxMin"));if(d.value<d.min||d.value>d.max)throw Error(this.F("valueRange"));}},getNodeBySubId:function(a){if(null==
a)return this.element?this.element[0]:null;a=a.subId;return"oj-slider-thumb-0"===a?this.widget().find(".oj-slider-thumb")[0]:"oj-slider-thumb-1"===a?this.widget().find(".oj-slider-thumb")[1]:"oj-slider-bar"===a||"oj-slider-bar-value"===a?this.widget().find("."+a)[0]:null},getSubIdByNode:function(a){if(null!=a){if(a.id===this.ZT(0)&&g(a).hasClass("oj-slider-thumb"))return{subId:"oj-slider-thumb-0"};if(a.id===this.ZT(1)&&g(a).hasClass("oj-slider-thumb"))return{subId:"oj-slider-thumb-1"};if(g(a).hasClass("oj-slider-bar"))return{subId:"oj-slider-bar"};
if(g(a).hasClass("oj-slider-bar-value"))return{subId:"oj-slider-bar-value"}}return null},_GetDefaultStyleClass:function(){return"oj-slider"},Yo:function(a,c){var d;d=null!==c?+c:c;if(isNaN(d))throw Error(this.F("optionNum",{option:a}));return d},iE:function(a){if(null===a)return 1;a=this.Yo("step",a);if(0>=a)throw Error(this.F("invalidStep"));if(null===a||0>=a)a=1;return a},WMa:function(){return this.Je.offset().left+this.Je.width()},eNa:function(){return this.Je.offset().left},X4:function(a){var c=
this.U7(),d=a[0].style,e=this;a.draggable({axis:this.Hd()?"y":"x",grid:c,disabled:!1,start:function(c){a[0]===g(e.cj)[0]?e.bj=0:a[0]===g(e.cj)[1]&&(e.bj=1);e.Mya(c,a)},drag:function(c,h){var k=h.position;e.Hd()?(d.left="",k.left=""):(d.top="",k.top="");e.zAa(c,a);e.Hd()?(0>k.top&&(k.top=0),k.top>e.Je.height()&&(k.top=e.Je.height())):(0>k.left&&(k.left=0),k.left>e.Je.width()&&(k.left=e.Je.width()));if(e.ei){var l;l=0===e.bj?g(e.cj[1]):g(e.cj[0]);if(e.Hd()){var m=a.outerHeight()/2,r=e.Je.offsetParent().offset().top;
l=l.offset().top+m-r}else m=a.outerWidth()/2,r=e.Je.offsetParent().offset().left,l=l.offset().left+m-r;0===e.bj?e.Hd()?k.top<l&&(k.top=l):e.gg()?k.left<l&&(k.left=l):k.left>l&&(k.left=l):e.Hd()?k.top>l&&(k.top=l):e.gg()?k.left>l&&(k.left=l):k.left<l&&(k.left=l)}},stop:function(c){this.style.width="";this.style.height="";e.$D(c,a)}})},rz:function(){this.options.disabled||(this.ei?this.cj.toArray().forEach(function(a){a=g(a);this.X4(a)},this):this.X4(this.mt))},QMa:function(){this.ei?this.cj.toArray().forEach(function(a){a=
g(a);a.is(".ui-draggable")&&a.draggable("disable")},this):this.mt.is(".ui-draggable")&&this.mt.draggable("disable")}})})();a.Components.Xa("ojSlider","editableValue",{properties:{disabled:{type:"boolean"},max:{type:"number"},min:{type:"number"},orientation:{type:"string"},rawValue:{type:"number|Array\x3cNumber\x3e",readOnly:!0,writeback:!0},step:{type:"number"},type:{type:"string"},value:{type:"number|Array\x3cNumber\x3e",writeback:!0}},methods:{},extension:{_hasWrapper:!0,_innerElement:"input",_widgetName:"ojSlider"}});
a.Components.register("oj-slider",a.Components.getMetadata("ojSlider"))});